home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / Everything / Stuff.cp < prev    next >
Encoding:
Text File  |  1998-09-06  |  6.6 KB  |  369 lines  |  [TEXT/CWIE]

  1. // Stuff.cp
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15.  
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. #include "DoScrap.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "ControlUtils.h"
  22. #include "DDocData.h"
  23. #include "EverythingEngine.h"
  24. #include "EverythingDoc.h"
  25.  
  26. #include "Stuff.h"
  27.  
  28.  
  29. //----------
  30. void    Stuff::Create (
  31.     AMDoc*            inDoc,
  32.     DDocData*        inData)
  33. {
  34.     Stuff*        winObj = new Stuff;
  35.  
  36.     if (winObj != nil) {
  37.         winObj->Open (inDoc);
  38.         winObj->ConnectToData (inData);
  39.     }
  40. }
  41.  
  42. //----------
  43. Stuff::Stuff ()
  44. {
  45.     mData = nil;
  46. }
  47.  
  48. //----------
  49. Stuff::~Stuff ()
  50. {
  51. }
  52.  
  53. //----------
  54. EverythingEngine*    Stuff::GetEngine ()
  55. {
  56.     return (EverythingEngine*) mDoc->mEngine;
  57. }
  58.  
  59. //----------
  60. void    Stuff::Open (
  61.     AMDoc*            inDoc)
  62. {
  63.     WindowPtr        window;
  64.     Handle            wftb;
  65.  
  66.     mDoc = inDoc;
  67.  
  68.     window = GetNewCWindow (WIND_Stuff, nil, (WindowPtr) -1L);
  69.     if (mDoc->mEngine->GetFilename () [0] != 0) {
  70.         SetWTitle (window, mDoc->mEngine->GetFilename ());
  71.     }
  72.     mWindow = window;
  73.     ((EverythingDoc*)mDoc)->mStuffPtr = window;
  74.  
  75.     SetWindowKind (window, 'AM');
  76.     SetWRefCon (window, (long) this);
  77.     SetPort (window);
  78.     SetInfo (window);
  79.  
  80.     wftb = ::GetResource ('Wftb', WIND_Stuff);
  81.  
  82.     CreateRootControl (window, &mRootControl);
  83.  
  84.     vScroll = nil;
  85.     hScroll = nil;
  86.  
  87.  
  88.     mToolsHandle = ::GetNewControl (CNTL_Tools, window);
  89.     SetWindowItemFont (mToolsHandle, wftb, 1);
  90.  
  91.  
  92.     mPopupsHandle = ::GetNewControl (CNTL_Popups, window);
  93.     SetWindowItemFont (mPopupsHandle, wftb, 2);
  94.  
  95.     mFromValuesList2Handle = ::GetNewControl (CNTL_FromValuesList2, window);
  96.     EmbedControl (mFromValuesList2Handle, mPopupsHandle);
  97.     SetWindowItemFont (mFromValuesList2Handle, wftb, 3);
  98.  
  99.     mFromMenuHandle = ::GetNewControl (CNTL_FromMenu, window);
  100.     EmbedControl (mFromMenuHandle, mPopupsHandle);
  101.     SetWindowItemFont (mFromMenuHandle, wftb, 4);
  102.  
  103.  
  104.     mListsHandle = ::GetNewControl (CNTL_Lists, window);
  105.     SetWindowItemFont (mListsHandle, wftb, 5);
  106.  
  107.     mTextListHandle = ::GetNewControl (CNTL_TextList, window);
  108.     EmbedControl (mTextListHandle, mListsHandle);
  109.     SetWindowItemFont (mTextListHandle, wftb, 6);
  110.     BuildTextListList (mTextListHandle);
  111.  
  112.     AdvanceKeyboardFocus (window);
  113.  
  114.     ShowWindow (window);
  115. }
  116.  
  117. //----------
  118. void    Stuff::Close ()
  119. {
  120.     mData->RemoveResponder (this);
  121.  
  122.     ((EverythingDoc*)mDoc)->mStuffPtr = nil;
  123.     SetInfo (nil);
  124.     HideWindow (mWindow);
  125.     DisposeWindow (mWindow);
  126.  
  127.     delete this;
  128. }
  129.  
  130. //----------
  131. void    Stuff::ConnectToData (
  132.     DDocData*        inData)
  133. {
  134.     mData = inData;
  135.     mData->AddResponder (this);
  136.  
  137.     SetControlValue (mToolsHandle, mData->GetTools ());
  138.     SetControlValue (mFromValuesList2Handle, mData->GetFromValuesList2 ());
  139.     SetControlValue (mFromMenuHandle, mData->GetFromMenu ());
  140.     SetListBoxChoice (mTextListHandle, mData->GetTextList ());
  141. }
  142.  
  143. //----------
  144. void    Stuff::DataChanged (
  145.     long        inDataID)
  146. {
  147.     if (inDataID == idTools) {
  148.         SetControlValue (mToolsHandle, mData->GetTools ());
  149.     }
  150.     if (inDataID == idFromValuesList2) {
  151.         SetControlValue (mFromValuesList2Handle, mData->GetFromValuesList2 ());
  152.     }
  153.     if (inDataID == idFromMenu) {
  154.         SetControlValue (mFromMenuHandle, mData->GetFromMenu ());
  155.     }
  156. }
  157.  
  158. //----------
  159. void    Stuff::BuildTextListList (
  160.     ControlHandle        inControl)
  161. {
  162.     ListHandle        list = GetListHandle (inControl);
  163.  
  164.     AddToList ("\pOne",   list);
  165.     AddToList ("\pTwo",   list);
  166.     AddToList ("\pThree", list);
  167.     AddToList ("\pInfinity",  list);
  168. }
  169.  
  170. //----------
  171. void    Stuff::Control (
  172.     ControlHandle        whichControl,
  173.     short                whichPart,
  174.     Point                where)
  175. {
  176.     Rect            bounds;
  177.     short            newValue;
  178.  
  179.     ExitCurField ();
  180.  
  181.     if (whichControl == mToolsHandle) {
  182.         if (TrackClick (mToolsHandle, where) != 0) {
  183.             mData->SetTools (GetControlValue (mToolsHandle));
  184.         }
  185.     }
  186.     if (whichControl == mFromValuesList2Handle) {
  187.         if (TrackClick (mFromValuesList2Handle, where) != 0) {
  188.             mData->SetFromValuesList2 (GetControlValue (mFromValuesList2Handle));
  189.         }
  190.     }
  191.     if (whichControl == mFromMenuHandle) {
  192.         if (TrackClick (mFromMenuHandle, where) != 0) {
  193.             mData->SetFromMenu (GetControlValue (mFromMenuHandle));
  194.         }
  195.     }
  196.     if (whichControl == mTextListHandle) {
  197.         if (TrackClick (mTextListHandle, where)) {
  198.             if (WasDoubleClick (mTextListHandle)) {
  199.             } else {    // single click
  200.                 mData->SetTextList (GetListBoxChoice (mTextListHandle));
  201.             }
  202.         }
  203.     }
  204. }
  205.  
  206. //----------
  207. void    Stuff::MouseIn (
  208.     Point        where,
  209.     short        modifiers)
  210. {
  211.     Rect        bounds;
  212.  
  213. }
  214.  
  215. //----------
  216. void    Stuff::ExitCurField ()
  217. {
  218.     ControlHandle    focus;
  219.  
  220.     GetKeyboardFocus (mWindow, &focus);
  221.  
  222.     if (focus == nil) {
  223.         // nothing to exit
  224.  
  225.     }
  226. }
  227.  
  228. //----------
  229. void    Stuff::TypeIn (
  230.     char        ch)
  231. {
  232.     ControlHandle    focus;
  233.     SInt16            keyCode;
  234.  
  235.     GetKeyboardFocus (mWindow, &focus);
  236.  
  237.     if ((ch == charEnter)
  238.     ||  (ch == charReturn)) {
  239.         ExitCurField ();
  240.     } else if (ch == charEsc) {
  241.     } else if (ch == charTab) {
  242.         DoTab ((curEvent.modifiers & optionKey) != 0);
  243.     } else if (focus != nil) {
  244.         keyCode = (SInt16)(curEvent.message & keyCodeMask);
  245.         HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
  246.         mDoc->mEngine->SetDirty ();
  247.     } else {
  248.         SysBeep (1);
  249.     }
  250. }
  251.  
  252. //----------
  253. void    Stuff::Resize ()
  254. {
  255.     /* application-specific code to resize items in window */
  256. }
  257.  
  258. //----------
  259. void    Stuff::Scroll (
  260.     short        newValue,
  261.     short        oldValue)
  262. {
  263.     /* application-specific code to scroll window */
  264.     if (gWhichScroll == vScroll) {
  265.     } else {    // horizontal
  266.     }
  267. }
  268.  
  269. //----------
  270. void    Stuff::DoUndo ()
  271. {
  272. } // DoUndo
  273.  
  274. //----------
  275. void    Stuff::DoCut ()
  276. {
  277.     TEHandle        curTE = GetCurTE ();
  278.  
  279.     if (curTE != nil) {
  280.         TECut (curTE);
  281.         mDoc->mEngine->SetDirty ();
  282.         scrapDirty = true;
  283.     }
  284. } // DoCut
  285.  
  286. //----------
  287. void    Stuff::DoCopy ()
  288. {
  289.     TEHandle        curTE = GetCurTE ();
  290.  
  291.     if (curTE != nil) {
  292.         TECopy (curTE);
  293.         scrapDirty = true;
  294.     }
  295. } // DoCopy
  296.  
  297. //----------
  298. void    Stuff::DoPaste ()
  299. {
  300.     TEHandle        curTE = GetCurTE ();
  301.  
  302.     if (curTE != nil) {
  303.         TEPaste (curTE);
  304.         mDoc->mEngine->SetDirty ();
  305.     }
  306. } // DoPaste
  307.  
  308. //----------
  309. void    Stuff::DoClear ()
  310. {
  311.     TEHandle        curTE = GetCurTE ();
  312.  
  313.     if (curTE != nil) {
  314.         TEDelete (curTE);
  315.         mDoc->mEngine->SetDirty ();
  316.     }
  317. } // DoClear
  318.  
  319. //----------
  320. void    Stuff::DoSelectAll ()
  321. {
  322.     TEHandle        curTE = GetCurTE ();
  323.  
  324.     if (curTE != nil) {
  325.         TESetSelect (0, 32767, curTE);
  326.     }
  327. } // DoSelectAll
  328.  
  329. //----------
  330. void    Stuff::DoShowClipboard ()
  331. {
  332. } // DoShowClipboard
  333.  
  334. //----------
  335. Boolean        Stuff::DoCommand (
  336.     long        inCommand)
  337. {
  338.     Boolean        result = true;
  339.  
  340.     switch (inCommand) {
  341.         case cmdUndo:
  342.                 DoUndo ();
  343.             break;
  344.         case cmdCut:
  345.                 DoCut ();
  346.             break;
  347.         case cmdCopy:
  348.                 DoCopy ();
  349.             break;
  350.         case cmdPaste:
  351.                 DoPaste ();
  352.             break;
  353.         case cmdClear:
  354.                 DoClear ();
  355.             break;
  356.         case cmdSelectAll:
  357.                 DoSelectAll ();
  358.             break;
  359.         case cmdShowClipboard:
  360.                 DoShowClipboard ();
  361.             break;
  362.  
  363.         default:
  364.                 result = false;
  365.     } // switch
  366.  
  367.     return result;
  368. }
  369.